package wc.servicelet; /**
 * @ClassName:${NAME}
 * @Author: 鹿建文
 * @Date: 2022/4/7  - 10:43
 * @Describe:
 */

import wc.Service.AdminService;
import wc.Service.Impl.AdminServiceImpl;
import wc.domain.Admin;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
       private AdminService adminService=new AdminServiceImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("postget");
        String username = request.getParameter("username");
        String password= request.getParameter("password");
        Admin admin =null;
        try {
            admin = adminService.login(username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (admin != null) {
            response.sendRedirect("index.html");
        } else{
            response.sendRedirect("erro.html");

        }

    }
}
